﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using ServiceStack.Redis;

namespace RedisKeyEditor
{
    public class Server
    {
        public string Name;
        public RedisNativeClient client;
        public int DbCount;
        public string encoding;

        public void close()
        {
            if(client!=null)
            {
                client.Dispose();
                client = null;
            }
        }
    }

    public class ServerDb : Server
    {
        public int db;
        public long KeyCount;
        
        public ServerDb(Server server)
        {
            Name = server.Name;
            client = server.client;
            DbCount = server.DbCount;
            encoding = server.encoding;
        }

        public bool SureDb()
        {
            if(client!=null&&client.Db!=db)
            {
                client.Db = db;
                return true;
            }
            return false;
        }
        
        public void Refresh()
        {
            if(client!=null)
            {
                if (client.Db != db) client.Db = db;
                KeyCount = client.DbSize;
            }
        }
    }

    public class ServerKey : Server
    {
        public int db;
        public string key;
        public string type;

        public ServerKey(Server server)
        {
            Name = server.Name;
            client = server.client;
            DbCount = server.DbCount;
            encoding = server.encoding;
        }
    }
}
